<!--
 * @Author: 张升 1562821455@qq.com
 * @Date: 2023-12-20 10:29:36
 * @LastEditors: 张升 1562821455@qq.com
 * @LastEditTime: 2023-12-20 10:32:27
 * @FilePath: \school-admin-webc:\Users\Administrator\Desktop\aa.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%A
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var as = [
        {
            "id": 3,
            "name": "A",
            "age": 20,
            "sex": "男"
        },
        {
            "id": 2,
            "name": "B",
            "age": 19,
            "sex": "女"
        },
        {
            "id": 1,
            "name": "D",
            "age": 21,
            "sex": "女"
        },
        {
            "id": 5,
            "name": "E",
            "age": 22,
            "sex": "男",
        }
    ]
    const sort = (arr, key) => {
        return arr.sort((a, b) => {
            return b[key] - a[key]
        })
    }
    console.log(sort(as, 'age'))
</script>
</html>